<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <link rel="shortcut icon" type="image/png" href="/static/favicon.ico" />
    <title>Goploader</title>
    <link rel="stylesheet" target="blank" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.css">
    <link rel="stylesheet" type="text/css" href="/static/milligram.min.css">
    <link rel="stylesheet" type="text/css" href="/static/style.css">
</head>

<body>
    <main class="wrapper">
        <section class="container" id="setup-form-section">
            <h5 class="title">Configure Goploader</h5>
            <p>
                You're seeing this page because your configuration file is either corrupted or it's the first time you start the application. Please fill in the following form to configure goploader. Once you're done, restart the application.
            </p>
            <p>Fields without default are mandatory.</p>
            <p style="color: #FF4848; display: none;" id="setup-errors"><b>It looks like some of the fields were ommited or have wrong values.</b></p>
            <form action="/" method="post" id="setup-form">
                <fieldset>
                    <h4>Server</h4>
                    <label for="name_server" class="label-inline"><b>Server Name</b></label>
                    <span class="error" id="name_server_err"></span>
                    <span class="float-right"><i>Your domain name or ip</i></span>
                    <input placeholder="example.tld" id="name_server" name="name_server" type="text">

                    <label for="port" class="label-inline"><b>Port</b></label>
                    <span class="float-right"><i>Port on which the server should listen</i></span>
                    <input placeholder="Default : 8080" id="port" name="port" type="text">

                    <input id="append_port" type="checkbox" name="append_port" value="true">
                    <label class="label-inline" for="append_port"><b>Append Port</b></label>
                    <span class="float-right"><i>Append the port to the server name</i></span>
                    <br />
                    <br />
                    <span class="float-right"><i>Serve HTTPS directly, requires both SSL cert and private key</i></span>
                    <input id="serve_https" type="checkbox" name="serve_https" value="true">
                    <label class="label-inline" for="serve_https"><b>Serve HTTPS</b></label>
                    <br />
                    <label for="ssl_cert" class="label-inline">SSL Certificate</label>
                    <input placeholder="Path to SSL Cert" id="ssl_cert" name="ssl_cert" type="text">
                    <label for="ssl_private_key" class="label-inline">SSL Private Key</label>
                    <input placeholder="Path to SSL Private Key" id="ssl_private_key" name="ssl_private_key" type="text">
                    <br />

                    <label for="loglevel" class="label-inline"><b>Log Level</b></label>
                    <span class="float-right"><i>Verbosity of the logs (disabled won't display logs)</i></span>
                    <br />
                    <select name="loglevel" id="loglevel">
                        <option value="debug">Debug</option>
                        <option value="info">Info</option>
                        <option value="error">Error</option>
                        <option value="disabled">Disabled</option>
                    </select>
                    <br />
                    <hr />

                    <h4>Uploads and Database</h4>

                    <label for="upload_dir" class="label-inline"><b>Upload Directory</b></label>
                    <span class="float-right"><i>Absolute or local directory in which files will be uploaded</i></span>
                    <input placeholder="Default : up/" id="upload_dir" name="upload_dir" type="text">

                    <label for="db" class="label-inline"><b>Database Path</b></label>
                    <span class="float-right"><i>Absolute or local path (and file name) to create</i></span>
                    <input placeholder="Default : goploader.db" id="db" name="db" type="text">

                    <label for="size_limit" class="label-inline"><b>Size Limit</b></label>
                    <span class="float-right"><i>Maximum size of the uploaded files in MB</i></span>
                    <input placeholder="Default : 20" id="size_limit" name="size_limit" type="text">

                    <label for="view_limit" class="label-inline"><b>View Limit</b></label>
                    <span class="float-right"><i>Maximum size for syntax-highlighted code to be shown in MB</i></span>
                    <input placeholder="Default : 5" id="view_limit" name="view_limit" type="text">

                    <label for="disk_quota" class="label-inline"><b>Disk Quota</b></label>
                    <span class="float-right"><i>Disk quota in GB. Set to 0 to disable.</i></span>
                    <input placeholder="Default : 0" id="disk_quota" name="disk_quota" type="text">
                    <hr />

                    <h4>URL Settings</h4>
                    <label for="uniuri_length" class="label-inline"><b>UniURI Length</b></label>
                    <span class="float-right"><i>The number of chars generated for URIs</i></span>
                    <input placeholder="Default : 10" id="uniuri_length" name="uniuri_length" type="text">

                    <label for="key_length" class="label-inline"><b>Key Length</b></label>
                    <span class="float-right"><i>Number of chars generated for AES keys</i></span>
                    <br />
                    <select name="key_length" id="key_length">
                        <option value="16">16 Chars</option>
                        <option value="32">32 Chars</option>
                    </select>
                    <br />
                    <hr />

                    <h4>Other Settings</h4>
                    <input id="fulldoc" type="checkbox" name="fulldoc" value="true">
                    <label class="label-inline" for="fulldoc"><b>Full Documentation</b></label>
                    <span class="float-right"><i>The homepage will display the full documentation</i></span>
                    <br />
                    <input id="no_web" type="checkbox" name="no_web" value="true">
                    <label class="label-inline" for="no_web"><b>No Web Interface</b></label>
                    <span class="float-right"><i>Don't provide a web interface</i></span>
                    <br />
                    <input id="sensitive_mode" type="checkbox" name="sensitive_mode" value="true">
                    <label class="label-inline" for="sensitive_mode"><b>Sensitive Mode</b></label>
                    <span class="float-right"><i>Display only the file upload form</i></span>
                    <br />
                    <input id="stats" type="checkbox" name="stats" value="true">
                    <label class="label-inline" for="stats"><b>Statistics</b></label>
                    <span class="float-right"><i>Display statistics</i></span>
                    <br />
                    <input id="always_download" type="checkbox" name="always_download" value="true">
                    <label class="label-inline" for="always_download"><b>Always Download</b></label>
                    <span class="float-right"><i>Never display the files in browser</i></span>
                    <br />
                    <input id="disable_encryption" type="checkbox" name="disable_encryption" value="true">
                    <label class="label-inline" for="disable_encryption"><b>Disable Encryption</b></label>
                    <span class="float-right"><i>Disable all encryption features</i></span>
                    <br />
                    <input id="prometheus_enabled" type="checkbox" name="prometheus_enabled" value="true">
                    <label class="label-inline" for="prometheus_enabled"><b>Enable Prometheus</b></label>
                    <span class="float-right"><i>Export Prometheus metrics</i></span>
                    <br />
                    <br />
                    <div style="text-align: center;">
                        <a class="button button-outline" id="submit-form" href="#">Send</a>
                    </div>
                </fieldset>
            </form>
        </section>
        <section class="container" id="submit-loader" style="display: none;">
            <div class="row">
                <div class="column column-offset-25">
                    <p>Please wait while Goploader is being configured.</p>
                </div>
            </div>
            <div class="row">
                <div class="column column-offset-50">
                    <div class="circle circle1"></div>
                    <div class="circle circle2"></div>
                </div>
            </div>
        </section>
        <section class="container" style="text-align: center; display: none;" id="setup-success">
            <h5 class="title">Goploader is now configured. You can restart the goploader server now.</h5>
            <p>
                A <code>conf.yml</code> file has be written containing your configuration. If you want to re-run this setup you can either delete that file or start the server with the -i (--initial) option.
            </p>
        </section>
    </main>
    <script src="/static/jquery.min.js"></script>
    <script>
        var loader = $("#submit-loader");
        $("#submit-form").click(function(e) {
            $("html, body").animate({
                scrollTop: 0
            }, "slow");
            $("#setup-form-section").fadeOut(400, function() {
                loader.fadeIn(400, function() {
                    var jqxhr = $.post("/", $("#setup-form").serialize());
                    jqxhr.done(function() {
                        loader.fadeOut(400, function() {
                            $("#setup-success").fadeIn();
                        });
                    });
                    jqxhr.fail(function(req, status, error) {
                        var error = jQuery.parseJSON(req.responseText);
                        for (var key in error) {
                            var label = $("label[for='" + key + "']");
                            label.append("&nbsp;&nbsp;&nbsp;<span style='color: #FF4848'>" + error[key] + "</span>");
                            $("#" + key).css("border", "0.1rem solid #FF4848");
                        }
                        loader.fadeOut(400, function() {
                            $("#setup-errors").show();
                            $("#setup-form-section").fadeIn();
                        });
                    });
                });
            });
        });
    </script>
</body>

</html>
